﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Block : MonoBehaviour {
	
	public int Row {get; set;}
	public int Column {get; set;}
	public int Color {get; set;}
	public bool IsFree {get; private set;}
	public GameObject Object {get; set;}

	public void Set (int color) {
		Color = color;
	}

	public void Generate () {
		Color = Random.Range(1,3);
	}
	
	public Block Pick () {
		IsFree = false;
		return this;
	}

	public void Release () {
		IsFree = true;
	}

	void OnClick () {
	
	}

	#region Override
	public override bool Equals(System.Object obj)
	{
		// If parameter cannot be cast to ThreeDPoint return false:
		Block p = obj as Block;
		if ((object)p == null)
		{
			return false;
		}
		
		// Return true if the fields match:
		return base.Equals(obj) && Color == p.Color;
	}
	
	public bool Equals(Block p)
	{
		// Return true if the fields match:
		return base.Equals((Block)p) && Color == p.Color;
	}
	
	public override int GetHashCode()
	{
		return base.GetHashCode() ^ Color;
	}

	public static bool operator ==(Block a, Block b)
	{
		// If both are null, or both are same instance, return true.
		if (System.Object.ReferenceEquals(a, b))
		{
			return true;
		}
		
		// If one is null, but not both, return false.
		if (((object)a == null) || ((object)b == null))
		{
			return false;
		}
		
		// Return true if the fields match:
		return a.Color == b.Color;
	}

	public static bool operator !=(Block a, Block b)
	{
		return !(a == b);
	}
	#endregion
}
